<!DOCTYPE HTML>
<html>
  <head>
	<?php echo Yaf_View_Simple::render("header.phtml"); ?>
  </head>
  <body>
	<?php echo Yaf_View_Simple::render("menu.phtml"); ?>
	<div class="container">
	  <div class="content">
		<form role="form" class="form-horizontal" id="beform" action="insert">
		  <fieldset>
			<div class="form-group">
			  <!-- Select Basic -->
			  <label class="control-label col-lg-2">Category:</label>
			  <div class="controls col-lg-4">
				<select class="form-control" name="category">
                  <?php foreach($category as $value){ ?>
				  <option value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
                  <?php } ?>
				</select>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="title">Title:</label>
			  <div class="col-lg-6">
				<input type="text" name="title" class="form-control" id="title" />
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="">Author:</label>
			  <div class="col-lg-4">
				<input type="text" name="author" class="form-control" id="author" />
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="description">Description:</label>
			  <div class="col-lg-6">
				<textarea name="Description" class="form-control" id="description" rows="5"></textarea>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label">Contents:</label>
			  <div class="col-lg-10">
				<textarea name="contents" class="form-control" id="contents"></textarea>
			  </div>
			</div>						
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="tag">Tag:</label>
			  <div class="col-lg-6">
				<input type="text" name="tag" class="form-control" id="tag" />
			  </div>
			</div>						
		  </fieldset>
		</form>
		<label class="col-lg-2 control-label"></label>
		<div class="col-lg-6">
		  <a  href="javascript:def.submit('#beform',null)" class="btn btn-primary">Submit</a>
		</div>
	  </div>
	</div>
	
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modellabel" aria-hidden="true">
	  <div class="modal-dialog">
		<div class="modal-content">
		  <div class="modal-header bg-default">
			<div class="modal-title" id="modallabel">
			  <h5 class="text-primary">Signal</h5>
			</div>
		  </div>
		  <div class="modal-body bg-primary">
			
		  </div>
		  <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Close
			</button>
		  </div>
		</div><!-- /.modal-content -->
	  </div><!-- /.modal -->
	</div>		

	<?php echo Yaf_View_Simple::render("footer.phtml"); ?>
    <script src="/asset/admin/js/summernote.js"></script>
	<script type="text/javascript">
     $(document).ready(function() {
         $('#contents').summernote({
             height: 300,             
             minHeight: null,         
             maxHeight: null,         
             focus: true,
             shortcuts: false,
             callbacks: {
                 onImageUpload: function(files) {
                     for(var i=0; i < files.length; i++) {
                         sendCMSFile(files[i]);
                     } 
                 }
             }
         });
     });
     function sendCMSFile(file) {
         if (file.type.includes('image')) {
             var name = file.name.split(".");
             name = name[0];
             var data = new FormData();
             data.append('file', file);
             $.ajax({
                 url: '/admin/image/upload',
                 type: 'post',
                 contentType: false,
                 cache: false,
                 processData: false,
                 dataType: 'json',
                 data: data,
                 success: function (data) {
                     var file = data.file;
                     var src = '/'+file.root_path+'/'+file.save_path+'/'+file.save_name;
                     $('#contents').summernote('insertImage', src);
                 },
                 error: function () {
                     console.error();
                 }
             });
         }
     }

	</script>    
  </body>
</html>
